package day0428.com.ch16threeLayer.dao.Impl;

import day0428.com.ch16threeLayer.dao.DateBaseTest;
import day0428.com.ch16threeLayer.dao.IUserDao;
import day0428.com.ch16threeLayer.entity.User;

import java.util.List;

/**
 * 作者：wangmaokang
 * 日期: 2021/4/28 10:01
 * 描述:
 */
public class UserDao implements IUserDao {


    @Override
    public User login(String name, String passWord) {
        for (User user : DateBaseTest.users) {
            if (name.equals(user.getName())&&passWord.equals(user.getPassWord())){
                return user;
            }
        }
        return null;
    }

    @Override
    public User getUserById(int id) {
        for (User user : DateBaseTest.users) {
            if (user.getId()==id){
                return user;
            }
        }
        return null;
    }

    @Override
    public List<User> getAllUsers() {
        return  DateBaseTest.users;
    }

    @Override
    public void addUser(User user) {
        DateBaseTest.users.add(user);
    }

    @Override
    public void deleteUserById(int id) {
        for (User user : DateBaseTest.users) {
            if (user.getId()==id){
               DateBaseTest.users.remove(user);
            }
        }
    }
}
